#!/bin/bash

# postinst script for sunwcsd
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown root:bin $BASEDIR/usr/share/man/man5
	chown root:bin $BASEDIR/lib
	chown root:bin $BASEDIR/lib/svc
	chown root:bin $BASEDIR/lib/svc/method
	chown root:bin $BASEDIR/usr/share/man
	chown root:root $BASEDIR/dev/fd
	chown root:root $BASEDIR/dev/term
	chown root:sys $BASEDIR/dev
	chown root:sys $BASEDIR/dev/dsk
	chown root:sys $BASEDIR/dev/ipnet
	chown root:sys $BASEDIR/dev/net
	chown root:sys $BASEDIR/dev/pts
	chown root:sys $BASEDIR/dev/rdsk
	chown root:sys $BASEDIR/dev/rmt
	chown root:sys $BASEDIR/dev/sad
	chown root:sys $BASEDIR/dev/swap
	chown root:sys $BASEDIR/dev/vt
	chown root:sys $BASEDIR/dev/zcons
	chown root:sys $BASEDIR/devices
	chown root:sys $BASEDIR/devices/pseudo
	chown root:sys $BASEDIR/etc
	chown root:sys $BASEDIR/etc/rcm
	chown root:sys $BASEDIR/etc/rcm/scripts
	chown root:sys $BASEDIR/etc/security
	chown root:sys $BASEDIR/lib/svc/manifest
	chown root:sys $BASEDIR/lib/svc/manifest/system
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/lib/svc/method/svc-syseventd ] && rm -f $BASEDIR/lib/svc/method/svc-syseventd
	else
	    chmod 0555 "$BASEDIR/lib/svc/method/svc-syseventd"
	    chown root:bin "$BASEDIR/lib/svc/method/svc-syseventd"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/path_to_inst ] && rm -f $BASEDIR/etc/path_to_inst
	else
	    [ -f $BASEDIR/etc/path_to_inst ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/path_to_inst $BASEDIR/etc/path_to_inst
	    chmod 0444 "$BASEDIR/etc/path_to_inst"
	    chown root:root "$BASEDIR/etc/path_to_inst"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/lib/svc/manifest/system/sysevent.xml ] && rm -f $BASEDIR/lib/svc/manifest/system/sysevent.xml
	else
	    chmod 0444 "$BASEDIR/lib/svc/manifest/system/sysevent.xml"
	    chown root:sys "$BASEDIR/lib/svc/manifest/system/sysevent.xml"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/dacf.conf ] && rm -f $BASEDIR/etc/dacf.conf
	else
	    chmod 0644 "$BASEDIR/etc/dacf.conf"
	    chown root:sys "$BASEDIR/etc/dacf.conf"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/devlink.tab ] && rm -f $BASEDIR/etc/devlink.tab
	else
	    [ -f $BASEDIR/etc/devlink.tab ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/devlink.tab $BASEDIR/etc/devlink.tab
	    chmod 0644 "$BASEDIR/etc/devlink.tab"
	    chown root:sys "$BASEDIR/etc/devlink.tab"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/driver_aliases ] && rm -f $BASEDIR/etc/driver_aliases
	else
	    [ -f $BASEDIR/etc/driver_aliases ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/driver_aliases $BASEDIR/etc/driver_aliases
	    chmod 0644 "$BASEDIR/etc/driver_aliases"
	    chown root:sys "$BASEDIR/etc/driver_aliases"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/driver_classes ] && rm -f $BASEDIR/etc/driver_classes
	else
	    [ -f $BASEDIR/etc/driver_classes ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/driver_classes $BASEDIR/etc/driver_classes
	    chmod 0644 "$BASEDIR/etc/driver_classes"
	    chown root:sys "$BASEDIR/etc/driver_classes"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/iu.ap ] && rm -f $BASEDIR/etc/iu.ap
	else
	    [ -f $BASEDIR/etc/iu.ap ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/iu.ap $BASEDIR/etc/iu.ap
	    chmod 0644 "$BASEDIR/etc/iu.ap"
	    chown root:sys "$BASEDIR/etc/iu.ap"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/minor_perm ] && rm -f $BASEDIR/etc/minor_perm
	else
	    [ -f $BASEDIR/etc/minor_perm ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/minor_perm $BASEDIR/etc/minor_perm
	    chmod 0644 "$BASEDIR/etc/minor_perm"
	    chown root:sys "$BASEDIR/etc/minor_perm"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/name_to_major ] && rm -f $BASEDIR/etc/name_to_major
	else
	    [ -f $BASEDIR/etc/name_to_major ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/name_to_major $BASEDIR/etc/name_to_major
	    chmod 0644 "$BASEDIR/etc/name_to_major"
	    chown root:sys "$BASEDIR/etc/name_to_major"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/security/device_policy ] && rm -f $BASEDIR/etc/security/device_policy
	else
	    [ -f $BASEDIR/etc/security/device_policy ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/device_policy $BASEDIR/etc/security/device_policy
	    chmod 0644 "$BASEDIR/etc/security/device_policy"
	    chown root:sys "$BASEDIR/etc/security/device_policy"
	fi
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/etc/security/extra_privs ] && rm -f $BASEDIR/etc/security/extra_privs
	else
	    [ -f $BASEDIR/etc/security/extra_privs ] || cp -ax $BASEDIR/usr/share/doc/sunwcsd/examples/extra_privs $BASEDIR/etc/security/extra_privs
	    chmod 0644 "$BASEDIR/etc/security/extra_privs"
	    chown root:sys "$BASEDIR/etc/security/extra_privs"
	fi
	# [ "$ZONEINST" = "1" ] || (mkdir -p $BASEDIR/dev && ln -f -s ./fd/2 $BASEDIR/dev/stderr)
	# [ "$ZONEINST" = "1" ] || (mkdir -p $BASEDIR/dev && ln -f -s ./fd/0 $BASEDIR/dev/stdin)
	# [ "$ZONEINST" = "1" ] || (mkdir -p $BASEDIR/dev && ln -f -s ./fd/1 $BASEDIR/dev/stdout)
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

